<?php

namespace App\Models;


use Illuminate\Database\Eloquent\Model;
use Dcat\Admin\Models\Role;


class AdminUser extends Model
{
    protected $table = 'admin_users';


    protected $fillable = [
        'username','mt_login','password','name','en_name','tjr_id','child','phone',
        'email','pay_password','profit_rate','is_auth','sfz_zimg','sfz_fimg','sfz_id','address',
        'bank_number','bank_type','bank_address','swift_code','is_lock','is_mail','is_withdrawal',
        'investment_amount','trade_balance','agent_balance','dry_password','avatar','users_leader_id',
        'usdt_id','usdt_img',
    ];

    // 投入表
    public function deposite()
    {
        return $this->hasMany(Deposite::class, 'user_id', 'id');
    }

    public function withdrawal()
    {
        return $this->hasMany(Withdrawal::class, 'user_id', 'id');
    }

    public function user_balance_log()
    {
        return $this->hasMany(UserBalanceLog::class, 'user_id', 'id');
    }

    // 自关联
    public function childs()
    {
        return $this->hasMany(get_class($this), 'tjr_id', 'id');
    }


    /**
     * A user has and belongs to many roles.
     *
     * @return BelongsToMany
     */
    public function roles()
    {
        $pivotTable = config('admin.database.role_users_table');
        $relatedModel = config('admin.database.roles_model');

        return $this->belongsToMany($relatedModel, $pivotTable, 'user_id', 'role_id');
    }


    public function users_leader()
    {
        return $this->belongsTo(UsersLeader::class, 'users_leader_id', 'id');
    }


    /***
     * 周结算
     * 一对多
     * @return mixed
     */
    public function week_checkout()
    {
        return $this->hasMany(WeekCheckout::class, 'user_id', 'id');
    }

    /***
     * 一对一
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function week_checkout_one()
    {
        return $this->hasOne(WeekCheckout::class, 'user_id', 'id');
    }






}
